import { QueryClient, useQuery } from "@tanstack/react-query";
import { LessonService } from "@/shared/api/api.lesson";
import { CompletedTaskService } from "@/shared/api/api.completedTask";
import { AxiosError, AxiosResponse } from "axios";

export function useIsThemeCompleted(themeId: number) {
    const queryClient = new QueryClient
    const { isLoading, error, data, refetch, isSuccess } =
        useQuery<any, (AxiosError<{ message: string }>)>(
            {
                queryKey: ['completed-themes', themeId],
                queryFn: () => CompletedTaskService.themeCompletionCheck(themeId),
                retry: 3
            }, queryClient
        )

    const errorMessage = error?.response?.data.message

    return {
        isLoading,
        response: data,
        errorMessage,
        refetch,
        isSuccess
    };
}